package com.ruoyi.develop.invoice.utils;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.develop.invoice.entity.Invoice;
import com.ruoyi.develop.invoice.entity.NewInvoice;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

public  class InvoiceUtils {
    public static Map<String,Object> getInvoiceInfo(String filePath){
        System.out.println(filePath);
        Map<String,Object> map = new HashMap<>();
        Path targetLocation = Paths.get(filePath);
        // 保存文件
        NewInvoice newInvoice = NewInvoiceExtractor.newPdfProcessInvoicesInFile(targetLocation.toAbsolutePath().toString());
        if (StringUtils.isNotBlank(newInvoice.getNumber())) {//新版发票
            map.put("number", newInvoice.getNumber());
            map.put("content", newInvoice.getContent());
            map.put("sellerName", newInvoice.getSellerName());
            map.put("date", newInvoice.getDate());
            map.put("amount", newInvoice.getAmount());
            map.put("taxAmount", newInvoice.getTaxAmount());
            map.put("totalAmount", newInvoice.getTotalAmount());
            map.put("inReserve2", newInvoice.getInReserve2());
        } else {//老版发票
            Invoice invoice = InvoiceExtractor.newPdfProcessInvoicesInFile(targetLocation.toAbsolutePath().toString());

            map.put("number", invoice.getNumber());
            map.put("content", invoice.getContent());
            map.put("code", invoice.getCode());
            map.put("date", invoice.getDate());
            map.put("amount", invoice.getAmount());
            map.put("taxAmount", invoice.getTaxAmount());
            map.put("totalAmount", invoice.getTotalAmount());
            map.put("inReserve2", invoice.getInReserve2());
        }
        return map;
    }








}
